package random.fox.p2p.presenter;

import android.text.TextUtils;

import java.io.File;

import random.fox.p2p.interactors.OnFinishSetInfoListener;
import random.fox.p2p.interactors.RegisterInteractor;
import random.fox.p2p.util.Util;
import random.fox.p2p.view.ISetInfoView;

/**
 * Created by wq on 15/3/21.
 */
public class SetInfoPresenterImpl implements SetInfoPresenter, OnFinishSetInfoListener {
    private ISetInfoView setInfoView;
    private RegisterInteractor interactor;
    public SetInfoPresenterImpl(ISetInfoView setInfoView, RegisterInteractor interactor) {
        this.setInfoView = setInfoView;
        this.interactor = interactor;
    }

    @Override
    public void setUserInfo(String nickName, File image, String birthday, int sex, String school, String city) {
        if (TextUtils.isEmpty(nickName)){
            setInfoView.noSetNickName();
            return;
        }

        if (!Util.checkNickName(nickName)){
            setInfoView.errorNickName();
            return;
        }

        if (!Util.checkBirthday(birthday)){
            setInfoView.errorBirthday();
            return;
        }

        if (sex == -1){ //性别没有设置
            setInfoView.noSetSex();
            return;
        }

        setInfoView.showProgress();
        interactor.setInfo(nickName,image,birthday,sex,school,city,this);
    }

    @Override
    public void onSuccess() {
        setInfoView.hideProgress();
        setInfoView.goToNext();
    }

    @Override
    public void onError(int errorCode) {
        setInfoView.hideProgress();
        setInfoView.showMessage("出错了");
    }
}
